import java.util.Scanner;

public class Knapsack1{
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                final int N = 1010;
                int n, V;
                int[] v = new int[N], w = new int[N];
                int[] dp = new int[N];

                n = sc.nextInt();
                V = sc.nextInt();
                for (int i = 1; i <= n; i++) {
                        v[i] = sc.nextInt();
                        w[i] = sc.nextInt();
                }

                // 第一阶段的动态规划
                for (int i = 1; i <= n; i++) {
                        for (int j = V; j >= v[i]; j--) {
                                dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
                        }
                }
                System.out.println(dp[V]);

                for (int i = 0; i < N; i++) {
                        dp[i] = 0;
                }

                for (int j = 1; j <= V; j++) {
                        dp[j] = -1;
                }

                for (int i = 1; i <= n; i++) {
                        for (int j = V; j >= v[i]; j--) {
                                if (dp[j - v[i]] != -1) {
                                        dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
                                }
                        }
                }

                System.out.println(dp[V] == -1 ? 0 : dp[V]);
        }
}
